<?php

class CategoryPriceList extends CWidget {

    public $category = 0;

    public function run() {
        $model = new buyServiceForm();
        if (isset(Yii::app()->session['userAttributes']))
            $model->attributes = Yii::app()->session['userAttributes'];
        $model->city = Yii::app()->params['regions'][Yii::app()->session['userRegion']['id']]['regionTitle'];
        $regionID = Yii::app()->session['userRegion']['id'] == 6 ? 1 : Yii::app()->session['userRegion']['id'];
        $tblName = !Yii::app()->user->isGuest ? '_model2serv_all' : '_model2serv_all_new';
        $sql = "SELECT * FROM {{" . $tblName . "}} p WHERE p.\"regionId\" = '" . $regionID . "' AND p.active = 1 AND p.\"modelId\" = " . $this->category . " ORDER BY p.\"serviceType\", p.sort";
        $values = Yii::app()->db->getCommandBuilder()->createSqlCommand($sql)->queryAll();
        $groups = array();
        $searches = [];
        foreach ($values as $value) {
            $groups[$value['serviceType']][] = $value;
            $searches[] = array('value' => $value['serviceTitle'], 'url' => $value['serviceId']);
        }
        $exchange = file_exists($file) ? file_get_contents($file) : 0;
        $this->render('categoryPriceList', array('searches' => $searches, 'groups' => $groups, 'model' => $model, 'exchange' => $exchange));
    }

}
